package com.java.simple.smallmybatis.binding;

import com.java.simple.smallmybatis.session.SqlSession;
import java.lang.reflect.Proxy;
import lombok.RequiredArgsConstructor;

/**
 * @author zhoujunlin
 * @date 2022年12月22日 14:21
 * @desc
 */
@RequiredArgsConstructor
public class MapperProxyFactory<T> {

    private final Class<T> mapperInterface;

    public T newInstance(SqlSession sqlSession) {
        MapperProxy<T> mapperProxy = new MapperProxy<>(sqlSession, mapperInterface);
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[]{mapperInterface}, mapperProxy);
    }

}
